<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of detallesVentasController
 *
 * @author MASTER
 */
class detallesVentasController extends AppController {

    //put your code here
    public $name = "detallesVentas";

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow();
        if (($this->Session->check('user')) && ($_SESSION['user'][0]['Tipo'] == 'admin')) {
            $this->Auth->allow();
        }
    }
 
    public function add($id) {
        $asdf = 0;
        if ($this->Session->check('carrito')) {
            $arreglo = $_SESSION['carrito']; //PASO ACTUAL CARRITO A UN ARREGLO
            for ($i = 0; $i < count($arreglo); $i++) {
                $this->detallesVenta->create();
                $data = array(
                    'detallesVenta' => array(
                        'venta_id' => $id,
                        'producto' => $arreglo[$i]['Producto'],
                        'precio' => $arreglo[$i]['Precio'],
                        'cantidad' => $arreglo[$i]['Cantidad'],
                        'subtotal' => $arreglo[$i]['Precio'] * $arreglo[$i]['Cantidad'],
                ));

                if ($this->detallesVenta->save($data)) {
                    $asdf = $asdf + 1;
                }
                $this->Session->delete('carrito');
                $this->set('detalleventas', $asdf);
                $this->layout = 'ajax';
            }
        }
    }

}

?>
